<?php
include '../meihe/common.php';

$act = isset($_GET['act']) ? daddslashes($_GET['act']) : null;

switch ($act) {
    case 'meihe':
        if ($islogin) {
            $conf['lhbamd'] = $conf['lhbamd'] ?? '';
            if ($conf['lhbamd']) {
                $blacklistValues = explode('|', $conf['lhbamd']);
                $functionCount = count($blacklistValues);
            } else {
                $functionCount = 0;
            }
            $result = array('code' => 0, 'yxts' => $yxts ?? '', 'count1' => $count1 ?? '', 'meihegg' => $gxbb['gggl'] ?? '', 'count2' => $count2 ?? '', 'jrkthy' => $jrkthy, 'scjr' => $scjr, 'vipyum' => $vipyum, 'duanljk' => $duanljk, 'fwjr' => $fwjr, 'ymzs' => $ymzs ?? '', 'fwjl' => $fwjl, 'sczs' => $sczs, 'hbmd' => $hbmd, 'hmd' => $functionCount, 'count3' => $count3 ?? '', 'count4' => $count4 ?? '', 'count5' => round($count5 ?? 0, 2), 'count6' => $count6, 'fjyum' => $fjyum, 'count7' => $count7, 'fhgg' => $hhgg ?? '', 'meihe20' => $jcbb ?? '', 'count8' => round($count8 ?? 0, 2), 'count9' => round($count9 ?? 0, 2), 'count10' => round($count10 ?? 0, 2), 'count11' => round($count11 ?? 0, 2), 'count12' => round($count12 ?? 0, 2), 'count13' => round($count13 ?? 0, 2), 'count14' => round($count14 ?? 0, 2), 'chart' => getDatePoint());
            exit(json_encode($result));
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'count':
        if ($islogin) {
            $count = $DB->count('SELECT count(*) FROM meihe_workorder WHERE status=0');
            exit('{"code":0,"count":' . $count . '}');
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'setClassSort':
        $id = intval($_GET['id']);
        $idd = intval($_GET['idd']);
        $DB->query("UPDATE meihe_api SET idd='{$idd}' WHERE id='{$id}'");
        exit('{"code":0,"msg":"succ"}');
        break;

    case 'hqsbm':
        if ($islogin) {
            $djyum = $_POST['djyum'];
            if (preg_match('/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i', $djyum)) {
                $roww = file_get_contents('' . $djyum . '/ajax.php?act=dlapi');
                $roww = json_decode($roww, true);
                if ($roww) {
                    $url_arr = parse_url($djyum);
                    if ($url_arr['host'] == $_SERVER['HTTP_HOST']) {
                        exit('{"code":-1,"msg":"无法对接自己站点！"}');
                        break;
                    }
                    $_var_3 = array();
                    foreach ($roww['data'] as $res) {
                        $_var_3[] = array('sbm' => $res['1'], 'mc' => $res['0']);
                    }
                    $result = array('code' => 0, 'msg' => 'succ', 'data' => $_var_3);
                    exit(json_encode($result));
                } else {
                    exit('{"code":-1,"msg":"打开对接网站失败,请检查是否同系统"}');
                }
            } else {
                exit('{"code":-1,"msg":"对接网址,请添加http(s)://头部协议"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'getMessage':
        if ($islogin) {
            $id = intval($_GET['id']);
            $row = $DB->get_row("SELECT * FROM meihe_message WHERE id='{$id}' limit 1");
            if ($row) {
                $result = array('code' => 0, 'msg' => 'succ', 'title' => $row['title'], 'type' => $row['type'], 'content' => $row['content'], 'date' => $row['addtime']);
                exit(json_encode($result));
            } else {
                exit('{"code":-1,"msg":"当前通知不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'workorder_complete':
        if ($islogin) {
            $id = intval($_GET['id']);
            $rows = $DB->get_row("SELECT * FROM meihe_workorder WHERE id='{$id}' limit 1");
            if ($rows) {
                if ($rows['status'] == 2) {
                    exit('{"code":-1,"msg":"当前工单已结单！"}');
                    break;
                }
                if ($DB->query("UPDATE meihe_workorder SET status=2 WHERE id='{$id}'")) {
                    exit('{"code":0,"msg":"完结工单成功"}');
                } else {
                    exit('{"code":-1,"msg":"完结工单失败！' . $DB->{'error'}() . '"}');
                }
            } else {
                exit('{"code":-1,"msg":"当前工单记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'workorder_reply':
        if ($islogin) {
            $id = intval($_GET['id']);
            $rows = $DB->get_row("SELECT * FROM meihe_workorder WHERE id='{$id}' limit 1");
            if ($rows) {
                if ($rows['status'] == 2) {
                    exit('{"code":-1,"msg":"当前工单已结单！"}');
                    break;
                }
                $content = str_replace(array('*', '^', '|'), '', trim(strip_tags(daddslashes($_POST['content']))));
                if (empty($content)) {
                    exit('{"code":-1,"msg":"补充信息不能为空！"}');
                    break;
                }
                $row = $DB->get_row("SELECT * FROM meihe_workorder WHERE id='{$id}' limit 1");
                $siterow = $DB->get_row("SELECT zid,user,qq FROM meihe_user WHERE zid='{$row['zid']}' limit 1");
                $mail_name = $siterow['qq'] . '@qq.com';
                $sub = $conf['sitename'] . '售后支持工单待反馈提醒';
                $content = explode('*', $row['content']);
                $content = mb_substr($content[0], 0, 16, 'utf-8');
                $text = '尊敬的' . $siterow['user'] . '：<br/>您于' . $row['addtime'] . '提交的售后支持工单(ID:' . $id . ') 需要您进一步提供相关信息。请登录网站后台“我的工单”查看详情并回复。若3天内您仍未回复此工单，我们会做完成工单处理。<a href="' . $authurl . 'user/workorder.php?my=view&id=' . $id . '" target="_blank">点此查看</a><br/><a href="' . $authurl . 'user/workorder.php?my=view&id=' . $id . '" target="_blank">工单标题：' . $content . '</a><br/>----------------<br/>' . $conf['sitename'];
                $msg = youfas($sub, $text);
                if (checkEmail($mail_name)) {
                    send_mail($mail_name, $sub, $msg);
                    $content = $rows['content'] . '*1^' . $date . '^' . $content;
                    if ($DB->query("UPDATE meihe_workorder SET content='{$content}',status=1 WHERE id='{$id}'")) {
                        exit('{"code":0,"msg":"回复工单成功"}');
                    } else {
                        exit('{"code":-1,"msg":"回复工单失败！' . $DB->{'error'}() . '"}');
                    }
                } else {
                    exit('{"code":-1,"msg":"邮件发送失败！"}');
                }
            } else {
                exit('{"code":-1,"msg":"当前工单记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'addduanl':
        if ($islogin) {
            $sbm = trim($_POST['sbm']);
            $name = $_POST['name'];
            if ($sbm == NULL || $name == NULL) {
                exit('{"code":0,"msg":"请确保识别码和名称不能为空！"}');
                break;
            }
            $rows = $DB->get_row("SELECT * FROM meihe_api WHERE sbm='{$sbm}' limit 1");
            if ($rows) {
                exit('{"code":0,"msg":"识别码已存在请更换一个！"}');
                break;
            }
            $duanl = $_POST['duanl'] ?? '';
            if (preg_match('/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i', $duanl)) {
                $rowss = $DB->get_row("SELECT * FROM meihe_api WHERE duanl='{$duanl}' limit 1");
                if ($rowss) {
                    exit('{"code":0,"msg":"接口域名已存在请更换一个！"}');
                    break;
                }
                $tbxy = $_POST['tbxy'] ?? '';
                $token = $_POST['key'] ?? '';
                $jkfl = $_POST['jkfl'];
                $fhzd = $_POST['fhzd'];
                $dljk = $_POST['dljk'];
                $djyum = $_POST['djyum'];
                $format = $_POST['format'];
                $duanl = $_POST['duanl'] ?? '';
                $jktz = $_POST['jktz'] ?? '';
                $sql = 'insert into `meihe_api` (`sbm`,`name`,`tbxy`,`djyum`,`token`,`apiurl`,`jkfl`,`format`,`fhzd`,`dljk`,`duanl`,`jktz`) values (\'' . $sbm . '\',\'' . $name . '\',\'' . $tbxy . '\',\'' . $djyum . '\',\'' . $token . '\',\'' . $apiurl . '\',\'' . $jkfl . '\',\'' . $format . '\',\'' . $fhzd . '\',\'' . $dljk . '\',\'' . $duanl . '\',\'1\')';
                if ($DB->query($sql)) {
                    exit('{"code":1,"msg":"添加短链接口成功！"}');
                } else {
                    exit('{"code":-1,"msg":"添加短链接口失败！"}');
                }
            } else {
                exit('{"code":0,"msg":"接口必须http(s)://开头 /尾"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'duanldit':
        if ($islogin) {
            $id = $_GET['id'];
            $rows = $DB->get_row("SELECT * FROM meihe_api WHERE id='{$id}' limit 1");
            if ($rows) {
                $sbm = trim($_POST['sbm']);
                $name = $_POST['name'];
                $token = $_POST['key'] ?? '';
                $tbxy = $_POST['tbxy'] ?? '';
                $jkfl = $_POST['jkfl'];
                $djyum = $_POST['djyum'];
                $apiurl = $_POST['apiurl'];
                $format = $_POST['format'];
                $fhzd = $_POST['fhzd'];
                $dljk = $_POST['dljk'];
                $duanl = $_POST['duanl'];
                $jktz = $_POST['jktz'] ?? '';

                if ($sbm == NULL || $name == NULL) {
                    exit('{"code":0,"msg":"请确保识别码和名称不能为空！"}');
                    break;
                }
                if ($DB->query("UPDATE meihe_api SET sbm='{$sbm}',tbxy='{$tbxy}',token='{$token}',jkfl='{$jkfl}',djyum='{$djyum}',name='{$name}',apiurl='{$apiurl}',format='{$format}',fhzd='{$fhzd}',dljk='{$dljk}',duanl='{$duanl}' WHERE id='{$id}'")) {
                    exit('{"code":1,"msg":"修改短链接口成功！"}');
                } else {
                    exit('{"code":-1,"msg":"修改短链接口失败！"}');
                }
            } else {
                exit('{"code":-1,"msg":"当前短链不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'plduanl':
        if ($islogin) {
            $aid = $_POST['aid'];
            $checkbox = $_POST['checkbox'];
            $i = 0;
            foreach ($checkbox as $id) {
                if ($aid == 1) {
                    $DB->query("UPDATE meihe_api SET jkfl=1 WHERE id='{$id}' limit 1");
                } elseif ($aid == 2) {
                    $DB->query("UPDATE meihe_api SET jkfl=2 WHERE id='{$id}' limit 1");
                } elseif ($aid == 4) {
                    $DB->query("DELETE FROM meihe_api WHERE id='{$id}' limit 1");
                }
                $i++;
            }
            exit('{"code":0,"msg":"成功改变' . $i . '个短链"}');
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'scjlgl':
        if ($islogin) {
            $aid = $_POST['aid'];
            $checkbox = $_POST['checkbox'];
            $i = 0;
            foreach ($checkbox as $id) {
                if ($aid == 2) {
                    $DB->query("DELETE FROM meihe_report WHERE id='{$id}' limit 1");
                }
                $i++;
            }
            exit('{"code":0,"msg":"成功改变' . $i . '个记录"}');
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'loggl':
        if ($islogin) {
            $aid = $_POST['aid'];
            $checkbox = $_POST['checkbox'];
            $i = 0;
            foreach ($checkbox as $id) {
                if ($aid == 2) {
                    $DB->query("DELETE FROM meihe_log WHERE id='{$id}' limit 1");
                }
                $i++;
            }
            exit('{"code":0,"msg":"成功改变' . $i . '个记录"}');
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'fwjlgl':
        if ($islogin) {
            $aid = $_POST['aid'];
            $checkbox = $_POST['checkbox'];
            $i = 0;
            foreach ($checkbox as $id) {
                if ($aid == 2) {
                    $DB->query("DELETE FROM meihe_log WHERE id='{$id}' limit 1");
                }
                $i++;
            }
            exit('{"code":0,"msg":"成功改变' . $i . '个记录"}');
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'workorder_change':
        if ($islogin) {
            $aid = $_POST['aid'];
            $checkbox = $_POST['checkbox'];
            $i = 0;
            foreach ($checkbox as $id) {
                $rows = $DB->get_row("SELECT * FROM meihe_workorder WHERE id='{$id}' limit 1");
                $content = str_replace(array('*', '^', '|'), '', trim(strip_tags(daddslashes($_POST['content']))));
                if ($rows && $rows['status'] < 2 && !empty($content)) {
                    $content = addslashes($rows['content']) . '*1^' . $date . '^' . $content;
                    $DB->query("UPDATE meihe_workorder SET content='{$content}',status=1 WHERE id='{$id}' limit 1");
                } elseif ($aid == 4) {
                    $DB->query("DELETE FROM meihe_workorder WHERE id='{$id}' limit 1");
                } elseif ($aid == 3) {
                    $DB->query("UPDATE meihe_workorder SET status=0 WHERE id='{$id}' limit 1");
                } elseif ($aid == 1) {
                    $DB->query("UPDATE meihe_workorder SET status=2 WHERE id='{$id}' limit 1");
                } elseif ($aid == 2) {
                    $DB->query("UPDATE meihe_workorder SET content='{$content}' WHERE id='{$id}' limit 1");
                }
                $i++;
            }
            exit('{"code":0,"msg":"成功改变' . $i . '个工单"}');
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'delworkorder':
        if ($islogin) {
            $id = intval($_GET['id']);
            $sql = "DELETE FROM meihe_workorder WHERE id='{$id}' limit 1";
            if ($DB->query($sql)) {
                exit('{"code":0,"msg":"删除成功！"}');
            } else {
                exit('{"code":-1,"msg":"删除失败！' . $DB->{'error'}() . '"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'od':
        if ($islogin) {
            if (!isset($_GET['test'])) {
                $update = '../api/check.json';
                // $authcode = md5('qq2136118039');
                $checkurl = $update . '?url=' . $_SERVER['HTTP_HOST'] . '&authcode=' . $authcode . '&ver=' . VERSION;
                $res = json_encode(['code' => 1, 'authcode' => md5('qq2136118039')]);
                $res = json_decode($res, true);
                $RemoteFile = $res['file'];
                $ZipFile = 'update.zip';
                copy($RemoteFile, $ZipFile) || exit('{"code":-1,"msg":"无法解压文件！请尝试几次"}');
                if (zipExtract($ZipFile, $_SERVER['DOCUMENT_ROOT'])) {
                    unlink($ZipFile);
                    exit('{"code":1,"msg":"更新程序完毕！<br>更新时间：' . $date . '"}');
                } else {
                    unlink($ZipFile);
                    exit('{"code":-2,"msg":"无法下载更新包文件！请重新更新或到官网下载更新包"}');
                }
            } else {
                $update = '../api/check.json';
                $authcode = md5('qq2136118039');
                $checkurl = $update . '?url=' . $_SERVER['HTTP_HOST'] . '&authcode=' . $authcode . '&ver=' . VERSION;
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;
    case 'sitedel':
        if ($islogin) {
            $id = intval($_GET['id']);
            $row = $DB->get_row("SELECT * FROM meihe_api WHERE id='{$id}' limit 1");
            if ($row) {
                $sql = "DELETE FROM meihe_api WHERE id='{$id}' limit 1";
                if ($DB->query($sql)) {
                    exit('{"code":0,"msg":"删除成功！"}');
                } else {
                    exit('{"code":-1,"msg":"删除失败！' . $DB->{'error'}() . '"}');
                }
            } else {
                exit('{"code":-1,"msg":"该短链记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;
    case 'kldlapi':
        if ($islogin) {
            $url = $_POST['url'];
            $key = $_POST['key'];
            $xitong = $_POST['xitong'];
            $url_arr = parse_url($url);
            if ($url_arr['host'] == $_SERVER['HTTP_HOST']) {
                exit('{"code":-1,"msg":"无法克隆自己站点！"}');
                break;
            }
            if (!$url || !$key) {
                exit('{"code":-1,"msg":"克隆KEY生成失败[' . $DB->{'error'}() . ']"}');
                break;
            }
            $url = '' . $url . 'ajax.php?act=klapi&key=' . $key;
            $urls = file_get_contents($url);
            if ($urls) {
                $data = json_decode($urls, true);
                if ($data['code'] == '-1') {
                    exit('{"code":-1,"msg":"克隆密钥错误！"}');
                    break;
                }
                if (preg_match('/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i', $url)) {
                    if ($data['code'] == '-1') {
                        exit('{"code":-1,"msg":"克隆密钥错误！"}');
                        break;
                    }
                    if ($_POST['qingkong'] == 1) {
                        $DB->query('TRUNCATE TABLE `meihe_api`');
                        $success = 0;
                        foreach ($data['data'] as $k => $v) {
                            $sbm = $v['sbm'];
                            $name = $v['name'];
                            $apiurl = $v['apiurl'];
                            $format = $v['format'];
                            $fhzd = $v['fhzd'];
                            $dljk = $v['dljk'];
                            $duanl = $v['duanl'];
                            $jktz = $v['jktz'];
                            $DB->query("INSERT INTO `meihe_api` (`sbm`,`name`,`duanl`,`apiurl`,`format`,`jktz`,`dljk`,`fhzd`) VALUES ('{$sbm}','{$name}','{$duanl}','{$apiurl}','{$format}','{$jktz}','{$dljk}','{$fhzd}')");
                            $success = $success + 1;
                        }
                        exit('{"code":1,"msg":"克隆完毕，成功执行 ' . $success . ' 个接口"}');
                    } else {
                        exit('{"code":-1,"msg":"克隆失败：可能有防火墙或非号号系统！"}');
                    }
                } else {
                    exit('{"code":-1,"msg":"http(s)://协议不能为空！"}');
                }
            } else {
                exit('{"code":-1,"msg":"克隆失败：可能有防火墙或非号号系统！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;
    case 'msgedit':
        if ($islogin) {
            $id = intval($_GET['id']);
            $row = $DB->get_row("SELECT * FROM meihe_message WHERE id='{$id}' limit 1");
            if ($row) {
                $title = daddslashes($_POST['title']);
                $type = intval($_POST['type']);
                $content = daddslashes($_POST['content']);
                $active = intval($_POST['active']);
                if ($title == NULL || $content == NULL) {
                    exit('{"code":-1,"msg":"修改错误,请确保每项都不为空！"}');
                    break;
                }
                if ($row['type'] != $type && $row['title'] != $title) {
                    $rows = $DB->get_row("SELECT * FROM meihe_message WHERE type='{$type}' and proid='{$proid}' and title='{$title}' limit 1");
                    if ($rows) {
                        exit('{"code":-1,"msg":"通知标题已存在！"}');
                        break;
                    }
                    $sql = "UPDATE `meihe_message` SET `type`='{$type}',`title`='{$title}',`content`='{$content}',`active`='{$active}' WHERE `id`='{$id}'";
                    if ($DB->query($sql)) {
                        exit('{"code":0,"msg":"修改通知成功！"}');
                    } else {
                        exit('{"code":-1,"msg":"修改通知失败！' . $DB->{'error'}() . '"}');
                    }
                } else {
                    $sql = "UPDATE `meihe_message` SET `type`='{$type}',`title`='{$title}',`content`='{$content}',`active`='{$active}' WHERE `id`='{$id}'";
                    if ($DB->query($sql)) {
                        exit('{"code":0,"msg":"修改通知成功！"}');
                    } else {
                        exit('{"code":-1,"msg":"修改通知失败！' . $DB->{'error'}() . '"}');
                    }
                }
            } else {
                exit('{"code":-1,"msg":"该通知记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;
    case 'chat_site':
        $zid = intval($_GET['zid']);
        if ($zid == 1) {
            if ($conf['kfqq']) {
                $qq = $conf['kfqq'];
                $user = $conf['admin_user'];
                $power = '<li class="list-group-item">权限：<font color="orange">平台站长</font></li>';
            } else {
                $qq = $conf['kfqq'];
                $user = $conf['admin_user'];
                $power = '<li class="list-group-item">权限：<font color="purple">贵族用户</font></li>';
            }
        } else {
            $row = $DB->get_row('select * from meihe_user where zid=\'' . $zid . '\' limit 1');
            if ($row) {
                $qq = $row['qq'];
                $user = $row['user'];
                if ($row['power'] == 2) {
                    $power = '<li class="list-group-item">权限：<font color="red">普通用户</font></li>';
                } else {
                    $power = '<li class="list-group-item">权限：<font color="purple">贵族用户</font></li>';
                }
            } else {
                exit('{"code":-1,"msg":"当前用户不存在！"}');
            }
        }

        $data = '<center><li class="list-group-item"><img src="//q4.qlogo.cn/headimg_dl?dst_uin=' . $qq . '&spec=100" alt="Avatar" width="60" height="60" style="border:1px solid #FFF;-moz-box-shadow:0 0 3px #AAA;-webkit-box-shadow:0 0 3px #AAA;border-radius: 50%;box-shadow:0 0 3px #AAA;padding:3px;margin-right: 3px;margin-left: 6px;"><br/>昵称：' . qqname($qq) . '</li></center><li class="list-group-item">代理ID：' . $zid . '</li><li class="list-group-item">用户名：' . $user . '</li><li class="list-group-item">QQ：' . $qq . '</li>' . $power;
        $result = array('code' => 0, 'msg' => 'succ', 'data' => $data, 'user' => $user);
        exit(json_encode($result));
        break;

    case 'setEndtime':
        if ($islogin) {
            $zid = intval($_POST['zid']);
            $month = intval($_POST['month']);
            $row = $DB->get_row("select * from meihe_user where zid={$zid} limit 1");
            if ($row['endtime'] > date('Y-m-d')) {
                $endtime = date('Y-m-d', strtotime("+ {$month} months", strtotime($row['endtime'])));
            } else {
                $endtime = date('Y-m-d', strtotime("+ {$month} months"));
            }
            $DB->query("update meihe_user set endtime='{$endtime}' where zid={$zid}");
            exit('{"code":0,"msg":"succ"}');
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'msg_active':
        if ($islogin) {
            $id = intval($_GET['id']);
            $row = $DB->get_row("SELECT * FROM meihe_message where id={$id} limit 1");
            if ($row) {
                $active = $row['active'] == 1 ? 0 : 1;
                $DB->query("update meihe_message set active='{$active}' where id={$id}");
                exit('{"code":0,"msg":"succ"}');
            } else {
                exit('{"code":-1,"msg":"该平台通知记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'msgdel':
        if ($islogin) {
            $id = intval($_GET['id']);
            $row = $DB->get_row("SELECT * FROM meihe_message where id={$id} limit 1");
            if ($row) {
                $sql = "DELETE FROM meihe_message where id={$id} limit 1";
                if ($DB->query($sql)) {
                    exit('{"code":0,"msg":"删除成功！"}');
                } else {
                    exit('{"code":-1,"msg":"删除失败！' . $DB->{'error'}() . '"}');
                }
            } else {
                exit('{"code":-1,"msg":"该平台通知记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'addmsg':
        if ($islogin) {
            $title = daddslashes($_POST['title']);
            $type = intval($_POST['type']);
            $content = daddslashes($_POST['content']);
            $date = date('Y-m-d H:i:s');
            if ($title == NULL || $content == NULL) {
                exit('{"code":-1,"msg":"修改错误,请确保每项都不为空！"}');
            }

            $rows = $DB->get_row("select * from meihe_message where type={$type} and proid={$proid} and title='{$title}' limit 1");
            if (!$rows) {
                $sql = 'insert into `meihe_message` (`type`,`title`,`content`,`addtime`,`active`) values (\'' . $type . '\',\'' . $title . '\',\'' . $content . '\',\'' . $date . '\',\'1\')';
                if ($DB->query($sql)) {
                    exit('{"code":0,"msg":"发布新通知成功！"}');
                } else {
                    exit('{"code":-1,"msg":"发布新通知失败！' . $DB->{'error'}() . '"}');
                }
            } else {
                exit('{"code":-1,"msg":"通知标题已存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'setSuper':
        if ($islogin) {
            $zid = intval($_GET['zid']);
            $row = $DB->get_row("select * from meihe_user where zid={$zid} limit 1");
            if ($row['power'] == 2) {
                $power = 1;
            } else {
                $power = 2;
            }
            $DB->query("update meihe_user set power='{$power}' where zid={$zid}");
            exit('{"code":0,"msg":"succ"}');
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'getServerIp':
        if ($islogin) {
            $ip = getServerIp();
            exit('{"code":0,"ip":"' . $ip . '"}');
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'epayurl':
        if ($islogin) {
            $id = intval($_GET['id']);
            $conf['payapi'] = $id;
            if ($url = pay_api()) {
                exit('{"code":0,"url":"' . $url . '"}');
            } else {
                exit('{"code":-1}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'duanl_active':
        if ($islogin) {
            $id = intval($_GET['id']);
            $row = $DB->get_row("SELECT * FROM meihe_api where id={$id} limit 1");
            if ($row) {
                $jktz = $row['jktz'] == 1 ? 0 : 1;
                $DB->query("update meihe_api set jktz='{$jktz}' where id={$id}");
                exit('{"code":0,"msg":"succ"}');
            } else {
                exit('{"code":-1,"msg":"该短链记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'haofl_active':
        if ($islogin) {
            $id = intval($_GET['id']);
            $row = $DB->get_row("SELECT * FROM meihe_class where id={$id} limit 1");
            if ($row) {
                $jktz = $row['jktz'] == 1 ? 0 : 1;
                $DB->query("update meihe_class set jktz='{$jktz}' where id={$id}");
                exit('{"code":0,"msg":"succ"}');
            } else {
                exit('{"code":-1,"msg":"该分类记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'fhgg_active':
        if ($islogin) {
            $id = intval($_GET['id']);
            $row = $DB->get_row("SELECT * FROM meihe_fhgg where id={$id} limit 1");
            if ($row) {
                $jktz = $row['jktz'] == 1 ? 0 : 1;
                $DB->query("update meihe_fhgg set jktz='{$jktz}' where id={$id}");
                exit('{"code":0,"msg":"succ"}');
            } else {
                exit('{"code":-1,"msg":"该分类记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录！"}');
        }
        break;

    case 'set':
        if ($islogin) {
            foreach ($_POST as $k => $v) {
                saveSetting($k, $v);
            }
            $ad = $CACHE->{'clear'}();
            if ($ad) {
                exit('{"code":0,"msg":"succ"}');
            } else {
                exit('{"code":-1,"msg":"修改设置失败[' . $DB->{'error'}() . ']"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'kthy':
        if ($islogin) {
            $thtime = date('Y-m-d') . ' 00:00:00';
            $rs = $DB->query("SELECT * FROM meihe_list WHERE `type`='1' AND date >= '{$thtime}'");
            $data = [];
            while ($res = $DB->{'fetch'}($rs)) {
                $data[] = array('id' => $res['id'], 'domain' => $res['domain'], 'qq' => $res['qq'], 'ktsj' => $res['date']);
            }
            $count = $DB->count('SELECT * FROM meihe_list WHERE `type`=\'1\' ');
            $jsonArray = ['code' => 0, 'msg' => '', 'count' => $count, 'data' => $data];
            print json_encode($jsonArray, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'ktmd':
        if ($islogin) {
            $thtime = date('Y-m-d') . ' 00:00:00';
            $rs = $DB->query("SELECT * FROM meihe_hbmd WHERE `type`='3' AND date >= '{$thtime}'");
            $data = [];
            while ($res = $DB->{'fetch'}($rs)) {
                $data[] = array('id' => $res['id'], 'domain' => $res['domain'], 'ktsj' => $res['date']);
            }
            $count = $DB->count('SELECT * FROM meihe_hbmd WHERE `type`=\'3\' ');
            $jsonArray = ['code' => 0, 'msg' => '', 'count' => $count, 'data' => $data];
            print json_encode($jsonArray, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'sso':
        if ($islogin) {
            $zid = intval($_GET['zid']);
            $userrow = $DB->get_row("select * from meihe_user where zid={$zid} limit 1");
            if ($userrow) {
                $session = md5($userrow['user'] . $userrow['pwd'] . $password_hash);
                $token = authcode("{$userrow['zid']}\	{$session}", 'ENCODE', SYS_KEY);
                setcookie('user_token', $token, time() + 3600 * 24 * 30, '/');
                exit('{"code":0,"msg":"登录成功,正在跳转！"}');
            } else {
                exit('{"code":-1,"msg":"该用户记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'mailtest':
        $mail_name = $conf['mail_recv'] ? $conf['mail_recv'] : $conf['mail_name'];
        if (!empty($mail_name)) {
            $result = send_mail($mail_name, '邮件发送测试。', '这是一封测试邮件！<br/><br/>来自：' . $conf['sitename']);
            if ($result == 1) {
                exit('{"code":0,"msg":"邮件发送成功！"}');
            } else {
                exit('{"code":-1,"msg":"邮件发送失败！"}');
            }
        } else {
            exit('{"code":-1,"msg":"您还未设置邮箱！"}');
        }
        break;

    case 'user_active':
        if ($islogin) {
            $zid = intval($_GET['zid']);
            $row = $DB->get_row("SELECT * FROM meihe_user where zid={$zid} limit 1");
            if ($row) {
                $active = $row['active'] == 1 ? 0 : 1;
                $DB->query("update meihe_user set active='{$active}' where zid={$zid}");
                exit('{"code":0,"msg":"succ"}');
            } else {
                exit('{"code":-1,"msg":"该用户记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'login':
        if ($islogin == 1) {
            exit('{"code":1,"msg":"登陆成功,欢迎回来!","url":"./"}');
        } else {
            if (isset($_GET['logout'])) {
                unset($_SESSION['admin_token']);
                exit('{"code":0,"msg":"您已成功注销本次登陆！"}');
            }

            if (isset($_POST['user']) && isset($_POST['pass'])) {
                $user = daddslashes($_POST['user']);
                $pass = daddslashes($_POST['pass']);
                if ($user === $conf['admin_user'] && $pass === $conf['admin_pwd']) {
                    unset($_SESSION['vc_code']);
                    $session = md5($user . $pass . $password_hash);
                    $token = authcode("{$user}\	{$session}", 'ENCODE', SYS_KEY);
                    $_SESSION['admin_token'] = $token;
                    @header('Content-Type: text/html; charset=UTF-8');
                    exit('{"code":1,"msg":"尊敬的' . $conf['admin_user'] . ',登录成功!","url":"./"}');
                } else {
                    exit('{"code":-1,"msg":"用户名或密码不正确！"}');
                }
            } else {
                exit('{"code":-1,"msg":"用户名或密码不正确！"}');
            }
        }
        break;

    case 'qrlogin':
        if (isset($_SESSION['saomalogin_qq']) && ($qq = $_SESSION['saomalogin_qq'])) {
            unset($_SESSION['saomalogin_qq']);
            if ($qq == $conf['kfqq']) {
                $user = $conf['admin_user'];
                $pass = $conf['admin_pwd'];
                $session = md5($user . $pass . $password_hash);
                $token = authcode("{$user}\	{$session}", 'ENCODE', SYS_KEY);
                $_SESSION['admin_token'] = $token;
                $qq = $conf['kfqq'];
                $name = qqname($qq);
                @header('Content-Type: application/json; charset=UTF-8');
                exit('{"code":0,"msg":"登录防洪平台成功！","qq":"' . $qq . '","name":"' . $name . '"}');
            } else {
                @header('Content-Type: application/json; charset=UTF-8');
                exit('{"code":-1,"msg":"当前QQ不存在，该QQ可能未绑定为站长QQ"}');
            }
        } else {
            @header('Content-Type: application/json; charset=UTF-8');
            exit('{"code":-2,"msg":"验证失败，请重新扫码"}');
        }
        break;

    case 'user_recharge':
        if ($islogin) {
            $zid = intval($_POST['zid']);
            $actdo = intval($_POST['actdo']);
            $rmb = floatval($_POST['rmb']);
            $row = $DB->get_row("select * from meihe_user where zid={$zid} limit 1");
            if ($row) {
                if ($rmb == '' || $rmb < 0) {
                    exit('{"code":-1,"msg":"金额输入不规范！"}');
                }
                if ($actdo == 1 && $rmb > $row['rmb']) {
                    $rmb = $row['rmb'];
                }
                if ($actdo == 0) {
                    $DB->query("update meihe_user set rmb=rmb+{$rmb} where zid={$zid}");
                } else {
                    $DB->query("update meihe_user set rmb=rmb-{$rmb} where zid={$zid}");
                }
                exit('{"code":0,"msg":"成功"}');
            } else {
                exit('{"code":-1,"msg":"当前用户不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'adduser':
        if ($islogin) {
            $power = intval($_POST['power']);
            $user = daddslashes($_POST['user']);
            $pwd = daddslashes($_POST['pwd']);
            $rmb = daddslashes($_POST['rmb']);
            $qq = daddslashes($_POST['qq']);
            $endtime = daddslashes($_POST['endtime']);
            $date = date('Y-m-d H:i:s');

            if (!$user || !$pwd || !$qq) {
                exit('{"code":-1,"msg":"请确保各项都不为空！"}');
            }

            if ($rmb == '' || $rmb < 0) {
                exit('{"code":-1,"msg":"余额设置不规范！"}');
            }

            $rows = $DB->get_row('select * from meihe_user where user=\'' . $user . '\' limit 1');
            if (!$rows) {
                $qqrow = $DB->get_row('select * from meihe_user where qq=\'' . $qq . '\' limit 1');
                if (!$qqrow) {
                    if ($power == 2) {
                        $power_name = '贵族用户';
                        $sql = 'insert into `meihe_user` (`upzid`,`power`,`endtime`,`user`,`pwd`,`rmb`,`qq`,`invitecode`,`addtime`,`status`) values (\'1\',\'' . $power . '\',\'' . $endtime . '\',\'' . $user . '\',\'' . $pwd . '\',\'' . $rmb . '\',\'' . $qq . '\',\'' . random(8) . '\',\'' . $date . '\',\'1\')';
                    } else {
                        $power_name = '普通用户';
                        $sql = 'insert into `meihe_user` (`upzid`,`power`,`user`,`pwd`,`rmb`,`qq`,`invitecode`,`addtime`,`status`) values (\'1\',\'' . $power . '\',\'' . $user . '\',\'' . $pwd . '\',\'' . $rmb . '\',\'' . $qq . '\',\'' . random(8) . '\',\'' . $date . '\',\'1\')';
                    }

                    if ($DB->query($sql)) {
                        exit('{"code":0,"msg":"添加' . $power_name . '成功！"}');
                    } else {
                        exit('{"code":-1,"msg":"添加' . $power_name . '失败！' . $DB->{'error'}() . '"}');
                    }
                } else {
                    exit('{"code":-1,"msg":"该QQ账号已存在！"}');
                }
            } else {
                exit('{"code":-1,"msg":"该用户名已存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'useredit':
        if ($islogin) {
            $zid = intval($_GET['zid']);
            $row = $DB->get_row("SELECT * FROM meihe_user where zid={$zid} limit 1");
            if ($row) {
                $power = intval($_POST['power']);
                $user = daddslashes($_POST['user']);
                $rmb = daddslashes($_POST['rmb']);
                $qq = daddslashes($_POST['qq']);
                $endtime = daddslashes($_POST['endtime']);
                $status = intval($_POST['status']);

                if (!$user || !$qq) {
                    exit('{"code":-1,"msg":"请确保各项都不为空！"}');
                }

                if ($rmb == '' || $rmb < 0) {
                    exit('{"code":-1,"msg":"余额设置不规范！"}');
                }

                if ($row['user'] != $user) {
                    $rows = $DB->get_row('select * from meihe_user where user=\'' . $user . '\' limit 1');
                    if ($rows) {
                        exit('{"code":-1,"msg":"该用户名已存在！"}');
                    }
                }

                if ($row['qq'] != $qq) {
                    $qqrow = $DB->get_row('select * from meihe_user where qq=\'' . $qq . '\' limit 1');
                    if ($qqrow) {
                        exit('{"code":-1,"msg":"该QQ账号已存在！"}');
                    }
                }

                if (empty(daddslashes($_POST['pwd']))) {
                    $sql = "update `meihe_user` set `power`='{$power}',`endtime`='{$endtime}',`rmb`='{$rmb}',`qq`='{$qq}',`status`='{$status}' where `zid`='{$zid}'";
                } else {
                    $sql = "update `meihe_user` set `power`='{$power}',`endtime`='{$endtime}',`rmb`='{$rmb}',`qq`='{$qq}',`pwd`='" . daddslashes($_POST['pwd']) . "'," . $sql . ",`status`='{$status}' where `zid`='{$zid}'";
                }

                if ($DB->query($sql)) {
                    exit('{"code":0,"msg":"修改成功！"}');
                } else {
                    exit('{"code":-1,"msg":"修改失败！' . $DB->{'error'}() . '"}');
                }
            } else {
                exit('{"code":-1,"msg":"该用户记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'user_czpass':
        if ($islogin) {
            $zid = intval($_GET['zid']);
            $row = $DB->get_row("SELECT * FROM meihe_user where zid={$zid} limit 1");
            if ($row) {
                if ($row['pwd'] == '123456') {
                    exit('{"code":-1,"msg":"该用户的密码已是初始密码！"}');
                } else {
                    $sql = "update `meihe_user` set `pwd`='123456' where `zid`='{$zid}'";
                    if ($DB->query($sql)) {
                        exit('{"code":0,"msg":"已将该用户的密码重置为123456[初始密码]"}');
                    } else {
                        exit('{"code":-1,"msg":"重置密码失败！' . $DB->{'error'}() . '"}');
                    }
                }
            } else {
                exit('{"code":-1,"msg":"该用户记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'kl_key':
        if ($islogin) {
            $key = random(20);
            saveSetting('hh_key', $key);
            $ad = $CACHE->{'clear'}();
            if ($ad) {
                exit('{"code":0,"msg":"克隆KEY生成成功"}');
            } else {
                exit('{"code":-1,"msg":"克隆KEY生成失败[' . $DB->{'error'}() . ']"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'hh_key':
        if ($islogin) {
            $key = random(20);
            saveSetting('hh_key', $key);
            $ad = $CACHE->{'clear'}();
            if ($ad) {
                exit('{"code":0,"msg":"克隆KEY重置成功"}');
            } else {
                exit('{"code":-1,"msg":"克隆KEY重置失败[' . $DB->{'error'}() . ']"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'bd_key':
        if ($islogin) {
            $key = random(20);
            saveSetting('hh8_key', $key);
            $ad = $CACHE->{'clear'}();
            if ($ad) {
                exit('{"code":0,"msg":"接口KEY生成成功"}');
            } else {
                exit('{"code":-1,"msg":"接口KEY生成失败[' . $DB->{'error'}() . ']"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'bd2_key':
        if ($islogin) {
            $key = random(20);
            saveSetting('hh8_key', $key);
            $ad = $CACHE->{'clear'}();
            if ($ad) {
                $_SESSION['hh8_key'] = TIMESTAMP;
                exit('{"code":0,"msg":"接口KEY重置成功"}');
            } else {
                exit('{"code":-1,"msg":"接口KEY重置失败[' . $DB->{'error'}() . ']"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'userdel':
        if ($islogin) {
            $zid = intval($_GET['zid']);
            $row = $DB->get_row("SELECT * FROM meihe_user where zid={$zid} limit 1");
            if ($row) {
                $sql = "DELETE FROM meihe_user where zid={$zid} limit 1";
                if ($DB->query($sql)) {
                    exit('{"code":0,"msg":"删除成功！"}');
                } else {
                    exit('{"code":-1,"msg":"删除失败！' . $DB->{'error'}() . '"}');
                }
            } else {
                exit('{"code":-1,"msg":"该用户记录不存在！"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'setSite':
        if ($islogin) {
            $zid = intval($_GET['zid']);
            $active = intval($_GET['active']);
            $DB->query("update meihe_user set status='{$active}' where zid={$zid}");
            exit('{"code":0,"msg":"succ"}');
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'fjvip':
        if ($islogin) {
            $id = intval($_GET['id']);
            $active = intval($_GET['active']);
            $DB->query("update meihe_list set type='{$active}' where id={$id}");
            exit('{"code":0,"msg":"切换状态成功！"}');
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'fhy':
        if ($islogin) {
            $id = intval($_GET['id']);
            $fhy = intval($_GET['fhy']);
            $DB->query("update meihe_list set fhy='{$fhy}' where id={$id}");
            exit('{"code":0,"msg":"切换状态成功！"}');
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'rkld':
        if ($islogin) {
            $id = intval($_GET['id']);
            $jklj = intval($_GET['jklj']);
            $DB->query("update meihe_host set jklj='{$jklj}' where id={$id}");
            exit('{"code":0,"msg":"切换状态成功！"}');
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'viphyxf':
        if ($islogin) {
            $id = intval($_POST['id']);
            $month = intval($_POST['month']);
            $row = $DB->get_row("select * from meihe_list where id={$id} limit 1");
            if ($row['endtime'] > date('Y-m-d')) {
                $endtime = date('Y-m-d', strtotime("+ {$month} months", strtotime($row['endtime'])));
            } else {
                $endtime = date('Y-m-d', strtotime("+ {$month} months"));
            }
            $DB->query("update meihe_list set endtime='{$endtime}' where id={$id}");
            exit('{"code":0,"msg":"succ"}');
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'kl2_key':
        if ($islogin) {
            $key = random(20);
            saveSetting('hh2_key', $key);
            $ad = $CACHE->{'clear'}();
            if ($ad) {
                exit('{"code":0,"msg":"接口密钥生成完毕"}');
            } else {
                exit('{"code":-1,"msg":"接口密钥生成失败[' . $DB->{'error'}() . ']"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;

    case 'hh2_key':
        if ($islogin) {
            $key = random(20);
            saveSetting('hh2_key', $key);
            $ad = $CACHE->{'clear'}();
            if ($ad) {
                $_SESSION['hh2_key'] = TIMESTAMP;
                exit('{"code":0,"msg":"接口密钥重置成功"}');
            } else {
                exit('{"code":-1,"msg":"接口密钥重置失败[' . $DB->{'error'}() . ']"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;
    case 'uploico':
        if (!($_POST['do'] == 'upload')) {
            exit('{"code":-1,"msg":"服务器错误"}');
        }
        $filename = $_FILES['file']['name'];
        $ext = substr($filename, strripos($filename, '.') + 1);
        $arr = array('png', 'jpg', 'gif', 'jpeg', 'webp', 'bmp');
        if (in_array($ext, $arr)) {
            if ($islogin) {
                $type = $_POST['type'];
                $filename = $type . '' . md5_file($_FILES['file']['favicon']) . '.png';
                $fileurl = 'assets/img/' . $filename;
                if (copy($_FILES['file']['tmp_name'], ROOT . 'assets/img/' . $filename)) {
                    exit('{"code":0,"msg":"succ","url":"' . $fileurl . '"}');
                } else {
                    exit('{"code":-1,"msg":"上传失败，请确保有本地写入权限"}');
                }
            } else {
                exit('{"code":-1,"msg":"未登录"}');
            }
        } else {
            exit('{"code":-1,"msg":"只支持上传图片文件"}');
        }
        break;
    case 'pngbj':
        if (!($_POST['do'] == 'upload')) {
            exit('{"code":-1,"msg":"服务器错误"}');
        }
        $filename = $_FILES['file']['name'];
        $ext = substr($filename, strripos($filename, '.') + 1);
        $arr = array('png', 'jpg', 'gif', 'jpeg', 'webp', 'bmp');
        if (in_array($ext, $arr)) {
            if ($islogin) {
                $type = $_POST['type'];
                $filename = $type . '' . md5_file($_FILES['file']['pngbj']) . '.png';
                $fileurl = 'assets/img/' . $filename;
                if (copy($_FILES['file']['tmp_name'], ROOT . 'assets/img/' . $filename)) {
                    exit('{"code":0,"msg":"succ","url":"' . $fileurl . '"}');
                } else {
                    exit('{"code":-1,"msg":"上传失败，请确保有本地写入权限"}');
                }
            } else {
                exit('{"code":-1,"msg":"未登录"}');
            }
        } else {
            exit('{"code":-1,"msg":"只支持上传图片文件"}');
        }
        break;
    case 'kl3_key':
        if ($islogin) {
            $key = random(0x00020);
            saveSetting('hh3_key', $key);
            $ad = $CACHE->{'clear'}();
            if ($ad) {
                exit('{"code":0,"msg":"接口密钥生成完毕"}');
            } else {
                exit('{"code":-1,"msg":"接口密钥生成失败[' . $DB->{'error'}() . ']"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;
    case 'hh3_key':
        if ($islogin) {
            $key = random(0x00020);
            saveSetting('hh2_key', $key);
            $ad = $CACHE->{'clear'}();
            if ($ad) {
                $_SESSION['hh3_key'] = TIMESTAMP;
                exit('{"code":0,"msg":"接口密钥重置成功"}');
            } else {
                exit('{"code":-1,"msg":"接口密钥重置失败[' . $DB->{'error'}() . ']"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;
    case 'kl4_key':
        if ($islogin) {
            $key = random(0x00020);
            saveSetting('hh4_key', $key);
            $ad = $CACHE->{'clear'}();
            if ($ad) {
                exit('{"code":0,"msg":"接口密钥生成完毕"}');
            } else {
                exit('{"code":-1,"msg":"接口密钥生成失败[' . $DB->{'error'}() . ']"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;
    case 'hh4_key':
        if ($islogin) {
            $key = random(0x00020);
            saveSetting('hh4_key', $key);
            $ad = $CACHE->{'clear'}();
            if ($ad) {
                $_SESSION['hh4_key'] = TIMESTAMP;
                exit('{"code":0,"msg":"接口密钥重置成功"}');
            } else {
                exit('{"code":-1,"msg":"接口密钥重置失败[' . $DB->{'error'}() . ']"}');
            }
        } else {
            exit('{"code":-1,"msg":"未登录"}');
        }
        break;
    default:
        exit('{"code":-4,"msg":"No Act"}');
}
